package com.yksj.healthtalk.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yksj.healthtalk.ui.R;

public class DoctorNavigationBarItem extends LinearLayout implements OnClickListener{

	private TextView tv;
	private RotateAnimation animationRotate;
	private ImageView iv;
	

	public DoctorNavigationBarItem(Context context) {
		super(context);
		init(context);
		// TODO Auto-generated constructor stub
	}

	public DoctorNavigationBarItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
		
	}

	private void init(Context context) {
		this.setOrientation(HORIZONTAL);
		tv = new TextView(context);
		tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,1.0f));
		tv.setText("Demo");
		tv.setGravity(Gravity.CENTER);
		tv.setSingleLine();
		//更新大小和颜色
		tv.setTextSize(12);
		tv.setTextColor(0xFF102933);
		addView(tv);
		iv = new ImageView(context);
		iv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
		iv.setImageResource(R.drawable.arrows);
		addView(iv); 
		setPadding(0, 0, 20, 0);
		this.setGravity(Gravity.CENTER);
		setOnClickListener(this);
	}
	
	
	public void setTextView(String str){
		tv.setText(str);
	}
	
	public String  getTextName(){
		return tv.getText().toString();
	}
	
	public void setTextView(int id){
		tv.setText(id);
	}
	
	
	/**
	 * 旋转动画
	 * @param toDegrees
	 * @param pivotXValue
	 * @param pivotYValue
	 * @return
	 */
	protected Animation animRotate(float toDegrees, float pivotXValue,
			float pivotYValue) {
		float fromDegrees ;
		if (toDegrees == 0) {
			 fromDegrees = 90;
		}else {
			 fromDegrees = 0;
		}
		animationRotate = new RotateAnimation(fromDegrees, toDegrees,
				Animation.RELATIVE_TO_SELF, pivotXValue,
				Animation.RELATIVE_TO_SELF, pivotYValue);
		animationRotate.setFillAfter(true);
		animationRotate.setDuration(500);
		animationRotate.setAnimationListener(null);
		return animationRotate;
	}

	@Override
	public void onClick(View v) {
		
	}
	
	public void startRotateAnimation(float toDegrees){
		iv.startAnimation(animRotate(toDegrees, 0.5f, 0.5f));
	}

}
